/*jslint maxerr: 50, indent: 4, browser: true */
/*global define */

(function () {
    "use strict";

    define("array.slice", ["mergeModules", "init", "array.length", "array.push"], function (make) {
        var buri = make.mergeModules(arguments),
            func = [].constructor.prototype.slice,
            config = {
                "compatability": {}
            },
            slice;

        if (!config.compatability.all && !config.compatability["array.push"] && typeof func === "function") {
            slice = function (array, begin, end) {
                return func.call(array, begin, end);
            };
        } else {
            slice = function (array, begin, end) {
                var length = buri.array.length(array),
                    i = begin || 0,
                    newArray = [];

                if (i < 0) {
                    i = length + i;
                }

                if (end < 0) {
                    length += end;
                } else if (end <= length) {
                    length = end;
                }

                while (i < length) {
                    buri.array.push(newArray, array[i]);
                    i += 1;
                }

                return newArray;
            };
        }

        slice.init = function (options) {
            buri.init(config, options);
            buri.array.length(config);
            buri.array.push(config);
        };

        return {
            "array": {
                "slice": slice
            }
        };
    });
}());
